<?php

namespace App\Http\Model;



class Bundle extends Base
{
    /** @var int 有效 */
    const STATUS_VALID = 1;
    /** @var int 无效 */
    const STATUS_INVALID = 0;

    /**
     * 定义数据库表名
     *
     * @var string
     */
    protected $table = 'bundle';

    /**
     * 定义主键名
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $fillable = [
        'price',
        'name',
        'provider_id'
    ];

    public function setDefault()
    {
        $this->status = 1;
        return $this;
    }

    /**
     * 捆绑包的商品
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function bundleGoods()
    {
        return $this->hasMany(BundleGoods::class, 'bundle_id', 'id');
    }

    /**
     * 所属供应商
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function provider()
    {
        return $this->belongsTo(Provider::class, 'provider_id', 'provider_id');
    }

    protected static function boot ()
    {
        parent::boot();

        static::creating(function (Bundle $bundle) {
            $bundle->status = 1;
        });
    }


}
